package com.jc.gateway.interception;//package com.jc.admin.interception;
//
//
//import com.lk.common.utils.JwtUtil;
//import io.jsonwebtoken.Claims;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//@Component
//public class LoginInterception implements HandlerInterceptor {
//    @Autowired
//    private JwtUtil jwtUtil;
//
//    public static ThreadLocal<PatientEntity> toThreadLocal = new ThreadLocal<>();
//
//    @Autowired
//    private PatientService patientService;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//
//        String token = request.getHeader("token");
//        if (token != null) {
//            //解析令牌
//            Claims claims = jwtUtil.parseJWT(token);
//            //解析成功  且是  patient 或  doctor 角色
//            if (claims != null && claims.get("roles").equals("patient")) {
//                PatientEntity patientEntity = patientService.getById(Integer.parseInt(claims.getId()));
//                toThreadLocal.set(patientEntity);
//                return true;
//            }else {
//                return false;
//            }
//        }
//        return true;
//    }
//
//
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
//        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
//    }
//}
